<?php
/*
 * MiniMe - a minimalistic OStatus complient microblogging tool
 * Copyright (C) 2010, Tuomas Koski - koski.tuomas@gmail.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * @author     Tuomas Koski <koski.tuomas@gmail.com>
 * @copyright  Tuomas Koski
 * @license    http://www.gnu.org/licenses/lgpl.txt
 */
$basedir = dirname(__FILE__);

require_once $basedir . '/../../../../classes/mm/xrd.php';
require_once $basedir . '/../../../../classes/mm/atom.php';

require_once $basedir . '/../../../../classes/mm/xml/element/builder/interface.php';
require_once $basedir . '/../../../../classes/mm/xml/element/builder/abstract.php';
require_once $basedir . '/../../../../classes/mm/xml/element/abstract.php';
require_once $basedir . '/../../../../classes/mm/xml/element/parent.php';
require_once $basedir . '/../../../../classes/mm/xml/element/parser.php';

require_once $basedir . '/../../../../classes/mm/xrd/element/hostmeta.php';
require_once $basedir . '/../../../../classes/mm/xrd/element/link.php';
require_once $basedir . '/../../../../classes/mm/xrd/element/host.php';
require_once $basedir . '/../../../../classes/mm/xrd/element/hostmeta/builder.php';


class Mm_Xrd_Element_HostmetaTest extends PHPUnit_Framework_TestCase {
    
    public function testParsingHostmetaFromIdentica () {
        $rawXML = '<?xml version="1.0" encoding="UTF-8"?>
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
  <hm:Host xmlns:hm="http://host-meta.net/xrd/1.0">identi.ca</hm:Host>
  <Link rel="lrdd" template="http://identi.ca/main/xrd?uri={uri}">
    <Title>Resource Descriptor</Title>
  </Link>
</XRD>';
        $builder = new Mm_Xrd_Element_Hostmeta_Builder($rawXML);
        $hostmeta = $builder->build();
        
        $this->assertEquals("identi.ca", $hostmeta->getHost()->value);
        $this->assertEquals("http://identi.ca/main/xrd?uri={uri}", $hostmeta->getLrddLink()->template);
        
        $expected = '<?xml version="1.0" encoding="UTF-8"?>
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0" xmlns:hm="http://host-meta.net/xrd/1.0">
  <hm:Host>identi.ca</hm:Host>
  <Link rel="lrdd" template="http://identi.ca/main/xrd?uri={uri}"/>
</XRD>
'; 
        $this->assertEquals($expected, $hostmeta->asXML());
    }
}